﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <h1 id="transportName">Unknown Transport</h1>

    <form id="sendmessage">
        <input type="text" id="data" />
        <input type="submit" value="Send" />
    </form>

    <ul id="messages"></ul>
    <script type="text/javascript">
        if (typeof Promise === 'undefined')
        {
            document.write('<script type="text/javascript" src="lib/signalr-client/signalr-clientES5.js"><\/script>');
        }
        else
        {
            document.write('<script type="text/javascript" src="lib/signalr-client/signalr-client.js"><\/script>');
        }
    </script>
    <script src="utils.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            let transportType = signalR.TransportType[getParameterByName('transport')] || signalR.TransportType.WebSockets;

            document.getElementById('transportName').innerHTML = signalR.TransportType[transportType];

            let url = 'http://' + document.location.host + '/chat';
            let connection = new signalR.HttpConnection(url, { transport: transportType, logger: new signalR.ConsoleLogger(signalR.LogLevel.Information) });

            connection.onreceive =  function(data) {
                let child = document.createElement('li');
                child.innerText = data;
                document.getElementById('messages').appendChild(child);
            };

            document.getElementById('sendmessage').addEventListener('submit', function(event) {
                let data = document.getElementById('data').value;
                connection.send(data);
                event.preventDefault();
            });

            connection.start().then(function() {
                console.log("Opened");
            }, function() {
                console.log("Error opening connection");
            });
        });
    </script>
</body>
</html>
